<?php
// +----------------------------------------------------------------------
// | Description: 图片上传
// +----------------------------------------------------------------------
// | Author: linchuangbin <linchuangbin@honraytech.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;

use app\common\controller\BaseController;

class Upload extends BaseController
{
    /**
     * 数据列表
     * @return Json
     */
    public function index()
    {

        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Methods: POST');
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
        $file = request()->file('file');
        if (!$file) {
        	return $this->json_responce(['error' => '请上传文件']);
        }

        $info = $file->validate(['ext'=>'jpg,png,gif'])->move(ROOT_PATH . DS . 'uploads');
        if ($info) {
            return $this->json_responce(  'uploads'. DS .$info->getSaveName());
        }

        return $this->json_responce(['error' =>  $file->getError()]);
    }
}
